//
//  MWShowroomInfoCell.m
//  XiRan-iOS
//
//  Created by liuyiming on 2019/10/26.
//  Copyright © 2019 Wood. All rights reserved.
//

#import "MWShowroomInfoCell.h"

@interface MWShowroomInfoCell ()

@property(nonatomic, strong) UIImageView *pictureIV;
@property(nonatomic, strong) UILabel *titleLB;
@property(nonatomic, strong) UILabel *descLB;
//@property(nonatomic, strong) UILabel *phoneHintLB;
//@property(nonatomic, strong) UILabel *phoneLB;
@property(nonatomic, strong) UILabel *timeHintLB;
@property(nonatomic, strong) UILabel *timeLB;
@property (nonatomic, strong) MWShowroomModel *showroom;
@end

@implementation MWShowroomInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupPageSubviews];
        [self layoutPageSubviews];
        return self;
    }
    return self;
}

- (void)setupData:(MWShowroomModel *)showroom {
//    NSDictionary *options = @{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType};
//    NSAttributedString *attrStr = [[NSAttributedString alloc] initWithData:[showroom.content dataUsingEncoding:NSUnicodeStringEncoding] options:options documentAttributes:nil error:nil];
//    _descLB.attributedText = attrStr;
    self.showroom = showroom;
    _descLB.text = showroom.introduce;

    NSString *urlStr = [NSString stringWithFormat:@"%@?x-oss-process=image/resize,h_420", showroom.image];
    [_pictureIV sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"lunbo"]];
    
    _titleLB.text = showroom.name;
//    _phoneLB.text = showroom.phone;
//    _phoneHintLB.text = [[MWConfigManager manager] objectForKey:@"sale_phone" defaultValue:@"销售顾问电话"];
//    _phoneLB.text = @"";
//    _phoneHintLB.text = @"";
    _timeLB.text = [NSString stringWithFormat:@"%@-%@", showroom.start_time, showroom.end_time];
    _timeHintLB.text = [[MWConfigManager manager] objectForKey:@"business_hours" defaultValue:@"销售顾问电话"];
}

- (void)setupPageSubviews {
    _pictureIV = [[UIImageView alloc] init];
    _pictureIV.layer.cornerRadius = 5;
    _pictureIV.layer.masksToBounds = YES;
    _pictureIV.contentMode = UIViewContentModeScaleAspectFit;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pictureIVClick)];
    [_pictureIV addGestureRecognizer:tap];
    [self.contentView addSubview:_pictureIV];
    
    _titleLB = [[UILabel alloc] init];
    _titleLB.font = MWFont(16);
    _titleLB.textColor = MWHexColor(@"#FD9F2B");
    [self.contentView addSubview:_titleLB];
    
    _descLB = [[UILabel alloc] init];
    _descLB.numberOfLines = 0;
    _descLB.font = MWFont(12);
    _descLB.textColor = MWHexColor(@"#666666");
    [self.contentView addSubview:_descLB];
    
//    _phoneHintLB = [[UILabel alloc] init];
//    _phoneHintLB.font = [UIFont boldSystemFontOfSize:15];
//    _phoneHintLB.textColor = MWHexColor(@"#333333");
//    [self.contentView addSubview:_phoneHintLB];
//
//    _phoneLB = [[UILabel alloc] init];
//    _phoneLB.font = MWFont(15);
//    _phoneLB.textColor = MWHexColor(@"#333333");
//    [self.contentView addSubview:_phoneLB];
    
    _timeHintLB = [[UILabel alloc] init];
    _timeHintLB.font = [UIFont boldSystemFontOfSize:15];
    _timeHintLB.textColor = MWHexColor(@"#333333");
    [self.contentView addSubview:_timeHintLB];
    
    _timeLB = [[UILabel alloc] init];
    _timeLB.font = MWFont(15);
    _timeLB.textColor = MWHexColor(@"#333333");
    [self.contentView addSubview:_timeLB];
}

- (void)layoutPageSubviews {
    [_pictureIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(16);
        make.left.equalTo(self.contentView).offset(16);
        make.right.equalTo(self.contentView).offset(-16);
        make.height.equalTo(@210);
    }];
    
    [_titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.pictureIV.mas_bottom).offset(12);
        make.left.equalTo(self.pictureIV);
        make.right.equalTo(self.pictureIV);
    }];
    
    [_descLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLB.mas_bottom).offset(8);
        make.left.equalTo(self.pictureIV);
        make.right.equalTo(self.pictureIV);
    }];
    
//    [_phoneHintLB mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.descLB.mas_bottom).offset(10);
//        make.left.equalTo(self.pictureIV);
//    }];
//
//    [_phoneLB mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.equalTo(self.phoneHintLB.mas_right).offset(10);
//        make.centerY.equalTo(self.phoneHintLB);
//    }];
    
    [_timeHintLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.descLB.mas_bottom).offset(8);
        make.left.equalTo(self.descLB);
        make.bottom.equalTo(self.contentView).offset(-16);
    }];
    
    [_timeLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeHintLB.mas_right).offset(10);
        make.centerY.equalTo(self.timeHintLB);
    }];
}

- (void)pictureIVClick {
    NSMutableArray *datas = [NSMutableArray array];
    YBIBImageData *browseModel = [[YBIBImageData alloc] init];
    browseModel.allowSaveToPhotoAlbum = YES;
    browseModel.imageURL =[NSURL URLWithString:[self.showroom.image stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
    [datas addObject:browseModel];
    YBImageBrowser *browser = [[YBImageBrowser alloc] init];
//    if ([MWConfigManager manager].language == 0) {
//        [YBIBCopywriter sharedCopywriter].type = YBIBCopywriterTypeSimplifiedChinese;
//    } else {
//        [YBIBCopywriter sharedCopywriter].type = YBIBCopywriterTypeEnglish;
//    }
    browser.defaultToolViewHandler.topView.operationType = YBIBTopViewOperationTypeSave;
    browser.dataSourceArray = datas;
    browser.currentPage = 1;
    [browser show];

}

@end
